package com.groupbuying.customer.controller;

import com.groupbuying.customer.service.CustomerWxinInfoService;
import com.groupbuying.customer.utils.apiresult.ApiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author gxy
 * @Description 会员微信信息相关接口
 * @Date 2019/5/14 10:11
 **/
@RestController
@RequestMapping("/customerWxinInfo")
public class CustomerWxinInfoController {

    @Autowired
    private CustomerWxinInfoService customerWxinInfoService;

    /**
     * @api {get} /customerWxinInfo/getOpenidByCustomerId 通过customerId查询openId
     * @apiExample
     * author mayunfei
     * tar 用于:TODO 未知调用方
     * date 2019/10/31
     * @apiGroup bus-customer
     * @apiVersion 1.0.0
     * @apiHeader {String} Authorization 用户授权token
     * @apiParam {String} customerId:微信customerId
     * @apiSuccess {String} Openid
     */
    @GetMapping("/getOpenidByCustomerId")
    public String getOpenidByCustomerId(String customerId){
        return customerWxinInfoService.getOpenidByCustomerId(customerId);
    }


    /**
     * @api {post} /customerWxinInfo/getPhoneNumByDecryptedData
     * @apiExample
     * author mayunfei
     * tar 用于:客户端小程序 调用
     * date 2019/10/31
     * @apiGroup bus-customer
     * @apiVersion 1.0.0
     * @apiHeader {String} Authorization 用户授权token
     * @apiParam {Map} decryptedData:加密手机号信息
     * @apiParam {Map}  iv:解密初始化偏移量
     * @apiParam {Map} code:用户小程序登录的code
     * @apiSuccess {ApiResult} success:登录成功; failure:请求
     * @apiSuccess {ApiResult}  failure:请求
     * @apiSuccess {ApiResult}  access_token失败
     */
    @PostMapping("/getPhoneNumByDecryptedData")
    public ApiResult getPhoneNumByDecryptedData(@RequestBody Map<String, String> parms){
        return customerWxinInfoService.getPhoneNumByDecryptedData(parms.get("decryptedData"),parms.get("iv"),parms.get("code"));
    }
}
